package com.jt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.SysUserDao;
import com.jt.pojo.User;
import com.jt.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUserServiceImpl implements SysUserService {

    private static final Map<Integer, String> paramMap = new HashMap<>();

    static {
        paramMap.put(1, "username");
        paramMap.put(2, "phone");
        paramMap.put(3, "email");
    }

    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public List<User> findObjects() {
        return sysUserDao.selectList(null);
    }

    /**
     * @param param 需要校验的数据
     * @param type  校验的类型 1.username 2.phone 3.email
     * @return
     */
    @Override
    public Boolean checkUser(String param, Integer type) {
        String column = paramMap.get(type);
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq(column, param);
        Boolean flag = sysUserDao.selectCount(wrapper) > 0;
        return flag;
    }

    @Override
    public User findUserById(Long userId) {
        return sysUserDao.selectById(userId);
    }
}
